package com.cgq.interceptor;

import java.util.Map;

import com.cgq.pro.entity.User;
import com.cgq.utils.Constants;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class LoginInterceptor extends AbstractInterceptor {

	private static final long serialVersionUID = 1L;

	@Override
	public String intercept(ActionInvocation invocation) throws Exception {

		// 取得请求相关的ActionContext实例   
		ActionContext ctx = invocation.getInvocationContext();  
		Map session = ctx.getSession();  
		User user=(User)session.get(Constants.USER_SESSION);
		
		//如果username不为空，代表用户已经登录，允许执行action里面的方法
		if(user!=null && user.getName()!=null){
			return invocation.invoke();
		}
		return "loginUI";
	}

}
